package customerEnter.Frame.conntroller;

import java.util.Map;

import customerEnter.Frame.Enum.RequestOrResponseJumpModeType;
import customerEnter.tool.WhetherToEmpty;

/**
 * Conntroller模型
 * 
 * 类名称：ConntrollerFrameModel 类描述： 创建人：dy 创建时间：2016-12-3 上午10:08:19
 * 
 */
public class ConntrollerFrameModel {

	protected BaseConntrollerFrameConntroView	ConntroView;

	protected Map<String, Object>				ConntroJsonObject;

	public ConntrollerFrameModel(BaseConntrollerFrameConntroView conntroView, Map<String, Object> conntroJsonObject) {
		ConntroView = conntroView;
		ConntroJsonObject = conntroJsonObject;
	}

	/**
	 * 成功的操作
	 */
	public void SetSuccessInfo(String url, RequestOrResponseJumpModeType type) {
		ConntroJsonObject.put("info", "操作成功");
		SetRequestDispatcherOrRedirect(type, url);
	}

	/**
	 * 失敗的操作
	 */
	public void SetFailure(String url, RequestOrResponseJumpModeType type) {
		ConntroJsonObject.put("info", "操作失敗");
		SetRequestDispatcherOrRedirect(type, url);
	}

	/**
	 * 成功的操作 默認轉發
	 */
	public void SetSuccessInfo(String url) {
		ConntroJsonObject.put("info", "操作成功");
		SetRequestDispatcherOrRedirect(RequestOrResponseJumpModeType.RequestDispatcher, url);
	}

	/**
	 * 失敗的操作 默認轉發
	 */
	public void SetFailure(String url) {
		ConntroJsonObject.put("info", "操作失敗");
		SetRequestDispatcherOrRedirect(RequestOrResponseJumpModeType.RequestDispatcher, url);
	}

	private void SetRequestDispatcherOrRedirect(RequestOrResponseJumpModeType type, String url) {
		if (!WhetherToEmpty.StringWhetherToEmpty(url)) {
			if ("RequestDispatcher".equals(type.getValue())) {
				ConntroView.RequestDispatcher(url);
			} else {
				ConntroView.Redirect(url);
			}
		}
	}

}
